package com.cj.ctyl.framework.core.controller;

import com.cj.ctyl.framework.core.page.PageDomain;
import com.cj.ctyl.framework.core.page.TableDataInfo;
import com.cj.ctyl.framework.core.page.TableSupport;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import java.util.List;

/**
 * @Author: Alex
 * @Description: 通用Controller
 * @Date: 2021/8/25
 */
public class BaseController {

    /**
     * 设置分页数据
     */
    protected void startPage() {
        PageDomain pageDomain = TableSupport.buildPageRequest();
        Integer pageNum = pageDomain.getPageNum();
        Integer pageSize = pageDomain.getPageSize();
        if (pageNum != null && pageSize != null) {
            PageHelper.startPage(pageNum, pageSize, pageDomain.getOrderBy());
        }
    }

    @SuppressWarnings({ "rawtypes", "unchecked" })
    protected TableDataInfo getDataTable(List<?> list)
    {
        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(200);
        rspData.setRows(list);
        rspData.setTotal(new PageInfo(list).getTotal());
        return rspData;
    }


}
